import { ApprovalData, WorkflowStep, NotificationItem } from './types';

/**
 * 模拟获取审批数据
 * @param id 审批ID
 * @returns 审批数据
 */
export const fetchApprovalData = async (): Promise<ApprovalData> => {
  // 模拟API请求延迟
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(mockApprovalData);
    }, 500);
  });
};

/**
 * 模拟获取通知记录
 * @param id 审批ID
 * @returns 通知记录列表
 */
export const fetchNotifications = async (id: string): Promise<NotificationItem[]> => {
  // 模拟API请求延迟
  await new Promise(resolve => setTimeout(resolve, 300));
  
  // 模拟返回数据
  return [
    {
      time: "2025-04-02 10:38:08",
      content: "系统已通知项目负责人进行审批"
    }
  ];
};

/**
 * 模拟提交审批操作
 * @param id 审批ID
 * @param action 操作类型
 * @param comment 备注信息
 * @returns 操作结果
 */
export const submitApprovalAction = async (
  id: string, 
  action: 'approve' | 'reject' | 'save', 
  comment?: string
): Promise<{ success: boolean; message: string }> => {
  // 模拟API请求延迟
  await new Promise(resolve => setTimeout(resolve, 500));
  
  // 模拟成功响应
  return {
    success: true,
    message: action === 'approve' 
      ? '审批已同意' 
      : action === 'reject' 
        ? '审批已拒绝' 
        : '操作已保存'
  };
};

/**
 * 模拟上传文件
 * @param file 文件对象
 * @returns 上传结果
 */
export const uploadFile = async (
  file: File
): Promise<{ success: boolean; fileUrl: string; fileName: string }> => {
  // 模拟API请求延迟
  await new Promise(resolve => setTimeout(resolve, 1000));
  
  // 模拟成功响应
  return {
    success: true,
    fileUrl: `https://example.com/files/${file.name}`,
    fileName: file.name
  };
};

// 模拟API响应数据
const mockApprovalData: ApprovalData = {
  approvalId: "AP-20250402-001",
  title: "项目需求内容变更",
  workflow: [
    {
      step: "开始",
      status: "completed",
      isCurrent: true
    },
    {
      step: "发起审批",
      status: "completed",
      handler: "鞠沁/80231866",
      handleTime: "2025-04-02 10:38:08",
      result: "请审批"
    },
    {
      step: "项目负责人审批",
      status: "pending",
      handler: "王宇华/80276430",
      assistHandler: "伍罡/80293464"
    }
  ],
  formData: {
    featureInfo: {
      featureName: "东方国际",
      featureCode: "IT990946-F8268695589",
      projectName: "专题特性选填测试",
      projectCode: "IT990946-E153",
      featureOwner: "伍罡/80293464"
    },
    changeInfo: {
      changeReason: "其他",
      changeDescription: "1212",
      attachments: []
    }
  },
  handlers: [
    {
      name: "伍罡",
      code: "80293464"
    }
  ]
}; 